home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacWT 0.9 / wt Mac Source / MacWT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-13  |  4.1 KB  |  206 lines  |  [TEXT/CWIE]

  1. /*
  2. ** File:        MacWT.c
  3. **
  4. ** Written by:    Bill Hayden
  5. **                Nikol Software
  6. **
  7. ** Copyright © 1995 Nikol Software
  8. ** All rights reserved.
  9. */
  10.  
  11.  
  12.  
  13. #include <stdio.h>
  14. #include "MacWT.h"
  15. #include "Music.h"
  16. #include "FileUtils.h"
  17. #include "StringUtils.h"
  18. #include "Failure.h"
  19. #include "Constants.h"
  20. #include "framebuf.h"
  21. #include "graphics.h"
  22. #include "fixed.h"
  23. #include "world.h"
  24. #include "view.h"
  25. #include "object.h"
  26. #include "render.h"
  27. #include "worldfile.h"
  28. #include "error.h"
  29. #include "input.h"
  30.  
  31.  
  32.  
  33.  
  34. static void GetScreenSize(short *width, short *height);
  35.  
  36.  
  37. OSErr    gMusicErr;
  38. fixed    start_x = 0, start_y = 0;
  39. World    *w;
  40. Object    *me, *him;
  41. View    *view;
  42.  
  43.  
  44.  
  45.  
  46. /*****************************************************************************/
  47.  
  48.  
  49.  
  50.  
  51. void InitMacWT(void)
  52. {
  53.     unsigned char        **versRsrc;
  54.     Graphics_info        *ginfo;
  55.     PhysicsModel        pm;
  56.     FILE                *fp;
  57.     short                width, height;
  58.     extern double        gravity;
  59.     extern Intent        gIntent;
  60.     Rect                r;
  61.     CursHandle            curs;
  62.     RgnHandle    GrayRgn = LMGetGrayRgn() ;
  63.  
  64.  
  65.     // remember the version
  66.  
  67.     if (!gWorldFile[0])
  68.         if (!SelectWorldFile(gWorldFile))
  69.             ExitToShell();
  70.  
  71.     //GetFilenameFromPathname(gWorldFile, WindowTitle);
  72.  
  73.     if ((versRsrc = (unsigned char **)Get1Resource('vers', 1)) != 0)
  74.         pcpy(gWTVersion, *versRsrc + 6);
  75.  
  76.     /* Open MacWT windows (well, dialogs)... */
  77.     
  78.     gWindow = GetNewDialog(rWindowID, nil, (WindowRef)-1);
  79.     if (!gWindow)
  80.         Fail(ResError(), __FILE__, __LINE__, TRUE);
  81.         
  82.     gBackgroundWindow = GetNewDialog(rBackgroundWindowID, nil, (WindowRef)gWindow);
  83.     if (!gBackgroundWindow)
  84.         Fail(ResError(), __FILE__, __LINE__, TRUE);
  85.         
  86.     UnionRect( &((**GrayRgn).rgnBBox), &(qd.screenBits.bounds), &r ) ;
  87.  
  88.     MoveWindow( (WindowRef)gBackgroundWindow, r.left, r.top, false ) ;
  89.     SizeWindow( (WindowRef)gBackgroundWindow, r.right-r.left, r.bottom-r.top, true ) ;
  90.     
  91.     ShowWindow((WindowRef)gWindow);
  92.     SelectWindow( (WindowRef)gWindow );            /* bring fore wind to front */
  93.  
  94.     GetScreenSize(&width, &height);
  95.  
  96.     SetPortWindowPort(gWindow);
  97.     TextFont(geneva);
  98.     TextSize(9);
  99.     TextFace(bold);
  100.     
  101.     // wt.c start
  102.     
  103.     gMusicErr = LoadMusicDriver();
  104.     
  105.     ginfo = InitGraphics(width, height);
  106.  
  107.     InitRenderer(ginfo->width, ginfo->height);
  108.     SetMem(&gIntent, 0, sizeof(gIntent));
  109.     
  110.     p2c(gWorldFile);
  111.     
  112.     if ((fp = fopen((char *)gWorldFile, "r")) == NULL)
  113.         {
  114.         fatal_error("The file “%s” could not be found.", (char *)gWorldFile);
  115.         return;
  116.         }
  117.         
  118.     curs = GetCursor(watchCursor);
  119.     SetCursor(*curs);
  120.      
  121.     w = read_world_file(fp);
  122.     fclose(fp);
  123.     
  124.     pm = (PhysicsModel)Get1Resource('Phys', 128);
  125.     
  126.     if (pm)
  127.         {
  128.         HLock((Handle)pm);
  129.         gravity = -(*pm)->gravity / 100.0;
  130.         me = new_object( (*pm)->mass,
  131.                          (*pm)->xsize / 10.0,
  132.                          (*pm)->ysize / 10.0,
  133.                          (*pm)->height / 10.0,
  134.                          (*pm)->drag / 100.0);    // load physics model
  135.         HUnlock((Handle)pm);
  136.         ReleaseResource((Handle)pm);
  137.         }
  138.     else
  139.         me = new_object(70.0, 1.5, 1.5, 1.8, 0.6);    // load in default physics model values
  140.  
  141.     him = new_object(70.0, 1.5, 1.5, 3.0, 0.6);
  142.     
  143.  
  144.     /* setup view */
  145.     view = CreateView(FIXED_HALF_PI, FIXED_ONE);
  146.  
  147.     add_object(w, me);
  148.     object_set_position(me, FIXED_TO_FLOAT(start_x), FIXED_TO_FLOAT(start_y), 0.0);
  149.  
  150.     add_object(w, him);
  151.     object_set_position(him, 3.0, 5.0, 0.0);
  152.  
  153.     AddFrame(him, ":textures:Man1.pictr");
  154.     AddFrame(him, ":textures:Man2.pictr");
  155.     AddFrame(him, ":textures:Man3.pictr");
  156.     AddFrame(him, ":textures:Man4.pictr");
  157.     
  158.     him->triggerticks = 25L;
  159.     
  160.     SetFrame(him, 0);
  161.     
  162.     SetCursor(&qd.arrow);
  163. }
  164.  
  165.  
  166.  
  167. /*****************************************************************************/
  168.  
  169.  
  170.  
  171. void DisposeMacWT(void)
  172. {
  173.     EndGraphics();
  174.  
  175.     if (!gMusicErr)
  176.         {
  177.         StopMusic();
  178.         DisposeMusicDriver();
  179.         }
  180. }
  181.  
  182.  
  183.  
  184. /*****************************************************************************/
  185.  
  186.  
  187.  
  188. static void GetScreenSize(short *width, short *height)
  189. {
  190.     short    ScreenSize, iType;
  191.     Handle    iHandle;
  192.     extern    Rect        gDestinationRect;
  193.     extern    Rect        gInformationRect;
  194.  
  195.  
  196.     ScreenSize = Alert(rScreenSize, nil);
  197.  
  198.     GetDialogItem( gWindow, ScreenSize, &iType, &iHandle, &gDestinationRect );
  199.     GetDialogItem( gWindow, 5, &iType, &iHandle, &gInformationRect );
  200.  
  201.     *width = gDestinationRect.right - gDestinationRect.left;
  202.     *height = gDestinationRect.bottom - gDestinationRect.top;
  203. }
  204.  
  205.  
  206.